package de.chronicals.superfart;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.plugin.PluginDescriptionFile;

public class SuperFart extends JavaPlugin
implements Listener
{
List<String> fire;
List<String> poop;

 
@SuppressWarnings({ "unchecked", "rawtypes" })
public void onEnable()
{
this.fire = new ArrayList();
this.poop = new ArrayList();
getServer().getPluginManager().registerEvents(this, this);
PluginDescriptionFile descFile = this.getDescription();
     System.out.println("[SuperFart] SuperFart " + descFile.getVersion() + " enabled!");
     System.out.println("[SuperFart] SuperFart idea by ItsJerryAndHerry!");
     System.out.println("[SuperFart] SuperFart maintained by CHRONICALSde!");
     System.out.println("[SuperFart] This SuperFart was compiled against Libigot #217");
     System.out.println("[SuperFart] Have fun ;)");
   }
 
   public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args)
   {
     if (!(sender instanceof Player)) {
	PluginDescriptionFile descFile = this.getDescription();
       sender.sendMessage(ChatColor.YELLOW + "[SF] " + ChatColor.RED + "You're not a player!");
       sender.sendMessage(ChatColor.YELLOW + "[SF] " + ChatColor.WHITE + "SuperFart Version " + descFile.getVersion() + " is installed");
       return true;
     }
     if (args.length != 1) {
       sender.sendMessage(ChatColor.GRAY + "[SF] " + ChatColor.RED + "Please type in Use: /sf <fire/poop>");
       PluginDescriptionFile descFile = this.getDescription();
       sender.sendMessage(ChatColor.GRAY + "[SF] " + ChatColor.WHITE + "SuperFart Version " + descFile.getVersion() + " is installed");
       return true;
     }
     String username = sender.getName().toLowerCase();
     if (args[0].equalsIgnoreCase("fire")) {
       if (!sender.hasPermission("superfart.fire")) {
         sender.sendMessage(ChatColor.GRAY + "[SF] " + ChatColor.RED + "You're not allowed to Firewalk, sry ;( .");
         return true;
       }
       if (this.fire.contains(username)) {
         this.fire.remove(username);
         sender.sendMessage(ChatColor.GRAY + "[SF] " + ChatColor.GREEN + "Firewalk is now disabled.");
         return true;
       }
       this.fire.add(username);
       sender.sendMessage(ChatColor.GRAY + "[SF] " + ChatColor.GREEN + "Firewalk is now enabled.");
       return true;
     }
     if (args[0].equalsIgnoreCase("poop")) {
       if (!sender.hasPermission("superfart.poop")) {
         sender.sendMessage(ChatColor.GRAY + "[SF] " + ChatColor.RED + "You're not allowed to poop, sry ;( .");
         return true;
       }
       if (this.poop.contains(username)) {
         this.poop.remove(username);
         sender.sendMessage(ChatColor.GRAY + "[SF] " + ChatColor.GREEN + "Poop is now disabled.");
         return true;
       }
       this.poop.add(username);
       sender.sendMessage(ChatColor.GRAY + "[SF] " + ChatColor.GREEN + "Poop is now enabled.");
       return true;
     }
     sender.sendMessage(ChatColor.GRAY + "[SF] " + ChatColor.RED + "Please type in /sf <fire/poop>");
PluginDescriptionFile descFile = this.getDescription();
       sender.sendMessage(ChatColor.GRAY + "[SF] " + ChatColor.WHITE + "SuperFart Version " + descFile.getVersion() + " is installed");
     return true;
   }
 
   @EventHandler
   public void onPlayerMove(PlayerMoveEvent event) {
     String username = event.getPlayer().getName().toLowerCase();
     if (this.fire.contains(username)) {
       Location loc = event.getFrom();
       Block block = loc.getBlock();
       if (block.getType() == Material.AIR)
         block.setType(Material.FIRE);
     }
     if (this.poop.contains(username)) {
       Location loc = event.getFrom();
       loc.getWorld().dropItemNaturally(loc, new ItemStack(Material.INK_SACK, 64, (short)3));
     }
   }
 }
